package com.aitaoxue.palx.fragment;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import android.view.View;
import android.widget.AdapterView;

import com.aitaoxue.palx.adapter.NewsAdapter;
import com.aitaoxue.palx.api.remote.AitaoXueApi;
import com.aitaoxue.palx.base.BaseListFragment;
import com.aitaoxue.palx.base.ListBaseAdapter;
import com.aitaoxue.palx.bean.ListEntity;
import com.aitaoxue.palx.bean.Test;
import com.aitaoxue.palx.bean.TestList;
import com.aitaoxue.palx.util.GsonUtil;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

public class HomeFragment extends BaseListFragment {

	protected static final String TAG = HomeFragment.class.getSimpleName();
	private static final String CACHE_KEY_PREFIX = "test_";

	@Override
	protected ListBaseAdapter getListAdapter() {
		return new NewsAdapter();
	}

	@Override
	protected String getCacheKeyPrefix() {
		return CACHE_KEY_PREFIX;
	}

	@Override
	protected ListEntity parseList(byte[] response) throws Exception {
		String test = new String(response);

		List<Test> list = GsonUtil.GsonToList(test,
				new TypeToken<List<Test>>() {
				}.getType());

		TestList testList = new TestList();
		testList.setTestLists(list);

		return testList;
	}

	@Override
	protected ListEntity readList(Serializable seri) {
		return (TestList)seri;
	}

	@Override
	protected void sendRequestData(Map<String, String> map) {
		AitaoXueApi.getBaseList(mhandler);
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		super.onItemClick(arg0, arg1, arg2, arg3);
	}
}
